---
title: "Gemfile.lock error with Rails on Docker"
date:  2020-05-03
category:  TechTips
---

I recently tried to build a rails project in Docker and hit the following error:

    Step 6/12 : RUN bundle install --without development test
    ---> Running in 327d0c474f28
    You must use Bundler 2 or greater with this lockfile.
    ERROR: Service 'web' failed to build: The command '/bin/sh -c bundle install --without development test' returned a non-zero code: 20


A few days earlier, the project was building fine, so this was surprising.  The
problem turned out to be quite simple to fix.  The issue was tthe specific
version of bundler that was used to install the gems and generate Gemfile.lock
was not the one being pulled in by the Ruby 2.5 image.

There are multiple options to get rid of the message, the best, probably, being
to simply install the version of bundler referenced in Gemfile.lock.  In my
case, the last two lines of the file looked like this.

*BUNDLED WITH  
2.0.2*

As far as I can tell, there are 3 ways to fix this:

1. Install the version of bundler referenced in Gemfile.lock
2. Removing this line from Gemfile.lock
3. Delete Gemfile.lock, re-install all gems from Gemfile

To install the specific version of bundler (option 1):

`gem install bundler -v 2.0.2

Option 1 is, I think, the correct solution, but the other 2 and 3 will probably
work in some cases.  You may get unintended side-effects though.  For number 2,
you may bump into version control issues / merge conflicts.  For number 3, you
will probably end up with multiple gems of different versions than you had
initially.  Stick with option 1, if you can.

If you have hit this error before, and know of a better solution, please let me
know.

